/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EVOLUTIVELIB_H__
#define __EVOLUTIVELIB_H__

#include "compatibility.h"

// XEVI : temporal definition
#include <float.h>
#include <exception>
#include <string>
#include <vector>

using namespace std;

namespace Evolutive {

#ifdef USE_OPENCV
	//! Function to store the image values to a ASCII file. Useful for debug purposes
	void EVOLUTIVELIB_API SaveImageData(IplImage *Image,string FileName);
#endif

	//! Defines a data type for rectangles vectors
	class EVOLUTIVELIB_API CRectVector : public std::vector<CvRect>{};

	//! Defines a data type for double vectors
	class EVOLUTIVELIB_API CDblVector : public std::vector<double>{};

	//! Define the comparison function to use with the qsort algorithm to sort in ascendant order
	static int DblCompareAsc( const void *arg1, const void *arg2 )
	{
		double a=*((double*)arg1);
		double b=*((double*)arg2);

		if(a==b) return 0;
		if(a>b) return 1;
		return -1;
	}
	//! Define the comparison function to use with the qsort algorithm to sort in descendant order
	static int DblCompareDesc( const void *arg1, const void *arg2 )
	{
		double a=*((double*)arg1);
		double b=*((double*)arg2);

		if(a==b) return 0;
		if(a<b) return 1;
		return -1;
	}

	//! Class to handle with the exceptions
	class EVOLUTIVELIB_API CEvolutiveLibException //: public exception
	{
	public:
		CEvolutiveLibException();
		CEvolutiveLibException(string Desc);
		CEvolutiveLibException(string Desc,string File,int Line);
		CEvolutiveLibException(string Desc,string File,int Line,string Function);
		virtual ~CEvolutiveLibException(void);
		string ToString(void);
		virtual const char *what(void);
		bool IsError(string Desc);

	private:
		string m_ErrorDesc;
		string m_File;
		string m_Function;
		int m_FileLine;
	};
}
#endif // __EVOLUTIVELIB_H__
